package com.dunshanasync.utils;

import java.util.regex.Pattern;

/**
 * @author .dunshan
 * @program: dunshan-pef
 * @description:
 * @date 2021-11-05 13:19:04
 */
public class RegexUtil {
    /**
     * Validate url
     *
     * @param url url address
     * @return true if legal
     */
    public static boolean validateUrl(String url) {
        String URL_PATTERN = "((http|ftp|https)://)(([a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6})|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\\#\\&%_\\./-~-]*)?";
        Pattern urlPattern = Pattern.compile(URL_PATTERN);
        return urlPattern.matcher(url).find();
    }
}
